//package com.zhdl.modules.assemblybolt;
//
//import com.google.common.eventbus.Subscribe;
//import com.project.common.util.DelayUtil;
//import com.zhdl.common.eventbus.center.EventBusCenter;
//import com.zhdl.common.ytools.HexToBitTools;
//import com.zhdl.modules.assemblybolt.web.req.AssemblyBoltData;
//import com.zhdl.modules.assemblybolt.web.req.TransportScrewData;
//import com.zhdl.modules.assemblybolt.service.AssemblyBoltService;
//import com.zhdl.modules.tools.CommonCallback;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.concurrent.ScheduledFuture;
//
//@Slf4j
//@Component
//public class TransportScrewProcess {
//    @Resource
//    public ThreadPoolTaskScheduler taskScheduler1;
//    boolean isRunning = false;
//
//    String microPort = "3", inspirePort = "7";
//    Map<String, ScheduledFuture<?>> mapSF = new HashMap<>();
//    TransportScrewData transportScrewData = new TransportScrewData();
//    private String PLCInfo;
//    @Resource
//    private AssemblyBoltService assemblyBoltService;
//
//    public void init() {
//        EventBusCenter.getEventBus().register(this);
//    }
//
//    public void startProcess() {
//        if (isRunning) {
//            return;
//        }
//        isRunning = true;
////        ScheduledFuture<?> scheduledFuture = taskScheduler1.scheduleWithFixedDelay(new Runnable() {
////            @Override
////            public void run() {
////              //  String s = HexToBitTools.readBitValueByHex(HexToBitTools.readHexValueByDecAddress(PLCInfo, 192));
////                    log.info("上料机-螺杆到位信号 翻转电机在取货等待位");
////                    mapSF.get("192,6,7").cancel(true);
////                    /*
////                        推螺杆电机 当前位置 如果在原点,则开始运动
////                     */
////
////            }
////        }, 100);
////        mapSF.put("192,6,7", scheduledFuture);
//        log.info("流程开始!!!!");
//        stepToTurnOverPosition();
//    }
//
//    public void stepToTurnOverPosition() {
//        stepToRunAxle6();
//    }
//
//    @Subscribe
//    public void onPLCInfo(AssemblyBoltData data) {
//        PLCInfo = data.getSiemensValue0To404();
//    }
//
//    public void release() {
//        isRunning = false;
//    }
//
//    public void stepToRunAxle6() {
//        //轴六运动 往前推
//        assemblyBoltService.plcControlMotorRun(6, 10, 0, false);
//        assemblyBoltService.plcControlMotorRunX(6, 10, transportScrewData.getAxle6XDistance());
//        assemblyBoltService.plcControlMotorRun(6, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//            assemblyBoltService.readPlcMotorRunDone(6, aBoolean -> {
//                log.info("电机前推完成-轴六");
//                stepToBackAxle6();
//            });
//        });
//
//    }
//
//    public void stepToBackAxle6() {
//        //轴六运动 往后回
//        assemblyBoltService.plcControlMotorRunX(6, 10, 0);
//        assemblyBoltService.plcControlMotorRun(6, 10, 0, false);
//        assemblyBoltService.plcControlMotorRun(6, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//            assemblyBoltService.readPlcMotorRunDone(6, aBoolean -> {
//                stepToBigPickTaut();
//            });
//            log.info("电机前推完成-轴六");
//        });
//
//    }
//
//    public void stepToRunAxle8() {
//        //轴八运动 翻转等螺杆
//        assemblyBoltService.plcControlMotorRun(8, 10, 0, false);
//        assemblyBoltService.plcControlMotorRunX(8, 10, transportScrewData.getAxle8ODistance());
//        assemblyBoltService.plcControlMotorRun(8, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//            assemblyBoltService.readPlcMotorRunDone(8, aBoolean -> {
//                stepToAxis5ZBack();
//            });
//            log.info("电机前推完成-轴8");
//        });
//
//    }
//
//    public void stepToBackAxle8() {
//        //轴八运动 原点送螺杆
//        assemblyBoltService.plcControlMotorRunX(8, 10, 0);
//        assemblyBoltService.plcControlMotorRun(8, 10, 0, false);
//        assemblyBoltService.plcControlMotorRun(8, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//            assemblyBoltService.readPlcMotorRunDone(8, aBoolean -> {
//                stepToAxis4XRun(transportScrewData.getAxle4_1Distance(), new CommonCallback<String>() {
//                    @Override
//                    public void statusCallback(String s) {
//                        stepToRotateRun(2000, new CommonCallback<String>() {
//                            @Override
//                            public void statusCallback(String s) {
//                                stepToRotateStop();
//                                stepToAxis4XRun(transportScrewData.getAxle4_2Distance(), new CommonCallback<String>() {
//                                    @Override
//                                    public void statusCallback(String s) {
//                                        DelayUtil.delayedExecution(1000, new Runnable() {
//                                            @Override
//                                            public void run() {
//                                                stepToAxis4XRun(transportScrewData.getAxle4_3Distance(), new CommonCallback<String>() {
//                                                    @Override
//                                                    public void statusCallback(String s) {
//                                                        stepToAxis5ZRun(transportScrewData.getAxle5_3Distance(), new CommonCallback<String>() {
//                                                            @Override
//                                                            public void statusCallback(String s) {
//                                                                stepToAxis5ZRun(0, new CommonCallback<String>() {
//                                                                    @Override
//                                                                    public void statusCallback(String s) {
//
//                                                                    }
//                                                                });
//                                                            }
//                                                        });
//                                                        stepToAxis4XRun(0, new CommonCallback<String>() {
//                                                            @Override
//                                                            public void statusCallback(String s) {
//
//                                                            }
//                                                        });
//                                                        stepToRotateRun(10000, new CommonCallback<String>() {
//                                                            @Override
//                                                            public void statusCallback(String s) {
//                                                                stepToRotateStop();
//                                                                stepToSmallPickPine();
//                                                                release();
//                                                            }
//                                                        });
//                                                    }
//                                                });
//                                            }
//                                        });
//                                    }
//                                });
//                            }
//                        });
//                    }
//                });
//            });
//            log.info("电机前推完成-轴六");
//        });
//
//    }
//
//    public void stepToBigPickTaut() {
//        assemblyBoltService.controlMicroMotorRun(microPort, 3, 1, s -> {
//            log.info("电机夹紧完成");
//        });
//        DelayUtil.delayedExecution(2000, new Runnable() {
//            @Override
//            public void run() {
//                stepToRunAxle8();
//            }
//        });
//    }
//
//    public void stepToBigPickPine() {
//        assemblyBoltService.controlMicroMotorRun(microPort, 3, 2, s -> {
//            log.info("电机松开完成");
//        });
//        DelayUtil.delayedExecution(2000, new Runnable() {
//            @Override
//            public void run() {
//                stepToAxis5ZRun(transportScrewData.axle5_2Distance, new CommonCallback<String>() {
//                    @Override
//                    public void statusCallback(String s) {
//                        stepToBackAxle8();
//                    }
//                });
//            }
//        });
//    }
//
//    public void stepToSmallPickTaut() {
//        assemblyBoltService.controlMicroMotorRun(microPort, 2, 1, s -> {
//            log.info("电机夹紧完成");
//        });
//        DelayUtil.delayedExecution(2000, new Runnable() {
//            @Override
//            public void run() {
//                stepToBigPickPine();
//            }
//        });
//    }
//
//    public void stepToSmallPickPine() {
//        assemblyBoltService.controlMicroMotorRun(microPort, 2, 2, s -> {
//            log.info("电机松开完成");
//        });
//    }
//
//    public void stepToRotateRun(int time,CommonCallback<String> callback) {
//        assemblyBoltService.controlMicroMotorRun(microPort, 1, 1, s -> {
//            log.info("电机旋转完成");
//        });
//        DelayUtil.delayedExecution(time, new Runnable() {
//            @Override
//            public void run() {
//                callback.statusCallback("0");
//            }
//        });
//    }
//
//    public void stepToRotateStop() {
//        assemblyBoltService.controlMicroMotorRun(microPort, 1, 2, s -> {
//            log.info("电机停止完成");
//        });
//    }
//
//    public void stepToAxis4XRun(float distance,CommonCallback<String> callback) {
//        assemblyBoltService.plcControlMotorRunX(4, 10, distance);
//        assemblyBoltService.plcControlMotorRun(4, 10, 0, false);
//
//        assemblyBoltService.plcControlMotorRun(4, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//            log.info("电机前推完成-轴四");
//            assemblyBoltService.readPlcMotorRunDone(4, aBoolean -> {
//                callback.statusCallback("0");
//            });
//        });
//
//    }
//
//    public void stepToAxis5ZRun(float distance,CommonCallback<String> callback) {
//        assemblyBoltService.plcControlMotorRunX(5, 10, distance);
//        assemblyBoltService.plcControlMotorRun(5, 10, 0, false);
//        assemblyBoltService.plcControlMotorRun(5, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//            assemblyBoltService.readPlcMotorRunDone(8, aBoolean -> {
//                callback.statusCallback("0");
//            });
//
//            log.info("电机前推完成-轴五");
//        });
//
//    }
//
//    public void stepToAxis4XBack() {
//        assemblyBoltService.plcControlMotorRunX(4, 10, 0);
//        assemblyBoltService.plcControlMotorRun(4, 10, 0, false);
//        assemblyBoltService.plcControlMotorRun(4, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//
//            assemblyBoltService.readPlcMotorRunDone(4, aBoolean -> {
//                stepToAxis5ZRun(transportScrewData.getAxle5_1Distance(), new CommonCallback<String>() {
//                    @Override
//                    public void statusCallback(String s) {
//                        stepToSmallPickTaut();
//                    }
//                });
//            });
//
//            log.info("电机原点完成-轴四");
//        });
//
//
//    }
//
//    public void stepToAxis5ZBack() {
//        assemblyBoltService.plcControlMotorRunX(5, 10,0);
//        assemblyBoltService.plcControlMotorRun(5, 10, 0, false);
//        assemblyBoltService.plcControlMotorRun(5, 10, 0, true);
//        DelayUtil.delayedExecution(200, () -> {
//
//
//            assemblyBoltService.readPlcMotorRunDone(5, aBoolean -> {
//                stepToAxis4XBack();
//            });
//            log.info("电机原点完成-轴四");
//        });
//
//
//    }
//}
